<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目成员管理')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目：</label>
                                <input type="text" name="projectName" id="projectName" disabled="disabled" />
                                <input type="hidden" name="projectId" id="projectId" th:value="${projectId}"/>
                            </li>
                            <li>
                                <label>用户名称：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>角色：</label>
                                <select name="roleId" id="roleId">
                                    <option value="">所有</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="pm:project:member:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="pm:project:member:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
				<a class="btn btn-danger" onclick="closeItem()">
				    <i class="fa fa-reply-all"></i> 关闭
				</a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: bootstrap-select-js" />
	<script th:src="@{/js/pm/project.js}"></script>
    <script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('pm:project:member:detail')}]];
        var listFlag = [[${@permission.hasPermi('pm:project:member:list')}]];
        var editFlag = [[${@permission.hasPermi('pm:project:member:edit')}]];
        var removeFlag = [[${@permission.hasPermi('pm:project:member:remove')}]];
        var prefix = ctx + "project/member";

        $(function() {
            // 加载角色列表
            loadRoleList();
            
            // 从URL参数获取项目ID
            var urlParams = new URLSearchParams(window.location.search);
            var projectId = urlParams.get('projectId');
            if (projectId) {
                $('#projectId').val(projectId);
                // 根据项目ID加载项目名称
                loadProjectInfo(projectId);
            }
            
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "项目成员",
                columns: [{
                    checkbox: true,
                    visible: removeFlag != 'hidden'
                },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '用户名称'
                },
                {
                    field: 'roleName',
                    title: '角色名称'
                },
                {
                    field: 'projectName',
                    title: '所属项目'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    formatter: function(value, row, index) {
                        return $.common.dateFormat(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i> 详细</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

		function add() {
		    var projectId = $("#projectId").val();
		    $.operate.add(projectId);
		}

    </script>
</body>
</html>